/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package percussiongenerator.commands;

import org.jfonia.connect5.intervals.Interval;

/**
 *
 * @author Jannes Plyson
 */
public class ChangeBegin implements ICommand{
    private Interval interval;
    private Object value;

    public ChangeBegin(Interval interval, Integer value){
        this.value = value;
        this.interval = interval;
    }

    public ChangeBegin(Interval interval, Long value){
        this.value = value;
        this.interval = interval;
    }

    public void execute() {
        if(value instanceof Integer){
            interval.getBeginNode().setValue((Integer)interval.getBegin()+(Integer)value);
            interval.getEndNode().setValue((Integer)interval.getEnd()-(Integer)value);
        }else if(value instanceof Long){            
            interval.getBeginNode().setValue((Long)interval.getBegin()+(Long)value);
            interval.getEndNode().setValue((Long)interval.getEnd()-(Long)value);
        }else{
            interval.getBeginNode().setValue((Double)interval.getBegin()+(Double)value);
            interval.getEndNode().setValue((Double)interval.getEnd()-(Double)value);
        }
    }

    public void undo() {
        if(value instanceof Integer){
            interval.getBeginNode().setValue((Integer)interval.getBegin()-(Integer)value);
            interval.getEndNode().setValue((Integer)interval.getEnd()+(Integer)value);
        }else if(value instanceof Long){
            interval.getBeginNode().setValue((Long)interval.getBegin()-(Long)value);
            interval.getEndNode().setValue((Long)interval.getEnd()+(Long)value);
        }else{
            interval.getBeginNode().setValue((Double)interval.getBegin()-(Double)value);
            interval.getEndNode().setValue((Double)interval.getEnd()+(Double)value);
        }
    }


}
